package com.read.scriptures.event;
import java.util.ArrayList;
import java.util.List;
//【bug1】
public class MEventManager {
    private static MEventManager instance;
    private List<MEventCallback> callbacks = new ArrayList<>();

    private MEventManager() {}

    public static MEventManager getInstance() {
        if (instance == null) {
            instance = new MEventManager();
        }
        return instance;
    }

    // 注册回调
    public void addCallback(MEventCallback callback) {
        if (!callbacks.contains(callback)) {
            callbacks.add(callback);
        }
    }

    // 移除回调
    public void removeCallback(MEventCallback callback) {
        callbacks.remove(callback);
    }

    // 发送事件（触发所有回调）
    public void postEvent(MEvent event) {
        for (MEventCallback callback : callbacks) {
            callback.onEvent(event);
        }
    }
}
